/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.helper.PageHelper;
import com.minierp.model.PhoneBook;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class PhoneBookValidator implements Validator {
	public boolean supports(Class clazz) {
		return PhoneBook.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		PhoneBook form = (PhoneBook) obj;
		if (form.getPerName() != null && !form.getPerName().trim().equals("")) {
			if (form.getMobile() != null && !form.getMobile().trim().equals("")) {
				if (!PageHelper.isMobileCode(form.getMobile())) {
					errors.rejectValue("mobile", "", "『手机』必须为11位数字");
				} else if (form.getQq() != null && !form.getQq().equals("")) {
					try {
						Long.parseLong(form.getQq());
					} catch (Exception arg4) {
						errors.rejectValue("qq", "", "『QQ』必须为数字");
					}
				} else if (form.getEmail() != null
						&& !form.getEmail().equals("")
						&& !PageHelper.isEmail(form.getEmail())) {
					errors.rejectValue("email", "", "『Email』格式不正确");
				}
			} else {
				errors.rejectValue("mobile", "", "请输入『手机』");
			}
		} else {
			errors.rejectValue("perName", "", "请输入『姓名』");
		}

	}
}